#include <arpa/inet.h>
#include "utils.h"

void stripNewlineCharacter(char *str)
{
    while(*str != '\0') {
        if (*str == '\n') {
            *str = '\0';
            break;
        }
        str++;
    }
}


void parseIPv4AddressToString(struct in_addr address, char *buffer)
{
    inet_ntop(AF_INET, &address, buffer, kIP_ADDRESS_STRING_MAX_LENGTH);
}


int tryParsingIPStringToInternetAddress(char *ip_address_str, struct in_addr *internet_address)
{
    if (inet_pton(AF_INET, ip_address_str, internet_address) != 1) {                   
        return kUTILS_TRYING_FUNCTIONS_RETURN_CODE_FAILED;
    }

    return kUTILS_TRYING_FUNCTIONS_RETURN_CODE_OK;
}